package com.heima.search.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.search.dtos.HistorySearchDto;
import com.heima.search.dtos.UserSearchDto;
import com.heima.search.pojos.ApUserSearch;
import com.heima.search.service.HistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/history")
public class HistoryController {

    @Autowired
    private HistoryService historyService;

    /**
     * 加载用户搜索记录
     *
     * @return 响应结果
     */
    @PostMapping("/load")
    public ResponseResult<List<ApUserSearch>> load() {
        List<ApUserSearch> apUserSearchList = historyService.load();
        return ResponseResult.okResult(apUserSearchList);
    }

    /**
     * 删除用户搜索记录
     *
     * @param historySearchDto 搜索记录id
     * @return 响应结果
     */
    @PostMapping("/del")
    public ResponseResult del(@RequestBody HistorySearchDto historySearchDto) {
        historyService.del(historySearchDto);
        return ResponseResult.okResult(null);
    }
}
